package com.mrd.gtimp.business.entity;

import com.mrd.gtimp.base.entity.Company;
import com.mrd.gtimp.base.entity.User;
import com.mrd.util.PkCleanerUtil;
import com.mrd.util.PkConfig;

import java.io.Serializable;
import java.util.Date;
import java.util.List;

import javax.persistence.CascadeType;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.OneToOne;

/**
 * <p> application name: sample <p> copyright: Copyright@2012 明睿达科技有限公司
 */

/**
 * 订舱信息
 *
 * @author winaya
 */
@Entity(name = "T_BIZ_BOOKING")
@org.hibernate.annotations.Entity(dynamicUpdate = true)
public class Booking extends BaseBusiness implements Serializable {

    private static final long serialVersionUID = 1L;

    /**
     * id
     */
    // @Id
    // @GeneratedValue(generator = "paymentableGenerator")
    // @GenericGenerator(name = "paymentableGenerator", strategy = "uuid")
    // @Column(name = "ID")
    // private String id;

    /**
     * 货物列表，一对多
     */
    @OneToMany(mappedBy = "booking", cascade = CascadeType.ALL)
    private List<Goods> goodses;

    /**
     * 收货人，从客户联系人列表获取
     */
    @ManyToOne
    @JoinColumn(name = "CONSIGNEE_ID")
    private Contacter consignee;

    /**
     * 大船公司，从大船公司列表获取
     */
    @ManyToOne
    @JoinColumn(name = "SHIP_COM_ID")
    private Company shipping;
    /**
     * 业务类型,从基础数据中获取
     */
    @Column(name = "BIZ_TYPE")
    private String businessType;
    /**
     * 起运港，从基础数据中获取
     */
    @Column(name = "ST_PORT")
    private String stPort;
    /**
     * 目的港，从基础数据中获取
     */
    @Column(name = "AR_PORT")
    private String arPort;
    /**
     * 船期要求
     */
    @Column(name = "SHIP_DATE")
    private String shipDate;
    /**
     * 总柜型柜量，格式为:柜量1*柜型1/柜量2*柜型2....，在前台进行格式控制
     */
    @Column(name = "CT_NUMTYPE")
    private String ctNumType;
    /**
     * 合作价格
     */
    @Column(name = "PRICE")
    private String price;
    /**
     * 备注
     */
    @Column(name = "REMARK")
    private String remark;
    /**
     * 货好时间
     */
    @Column(name = "GF_DATE")
    private Date gfDate;
    /**
     * 以下信息为反馈信息
     */
    /**
     * so号码
     */
    @Column(name = "SO")
    private String so;
    /**
     * 截关时间
     */
    @Column(name = "CT_DATE")
    private Date ctDate;
    /**
     * 预计头程时间
     */
    @Column(name = "HD_DATE")
    private Date hdDate;
    /**
     * 电子版SO
     */
    @OneToOne
    @JoinColumn(name = "SO_FILE_ID")
    private Attachment soDoc;
    /**
     * 舱单状态，要求与基础数据表匹配
     */
    @Column(name = "STATE")
    private String bookingState;
    /**
     * 柜和封条信息
     */
    @OneToMany(mappedBy = "booking")
    private List<Container> containers;
    /**
     * 操作类型
     */
    @Column(name = "OPERATION_TYPE")
    private String operationType;
    // /**
    // * 出口装船时间
    // */
    // @Column(name = "UNLOADING_TIME")
    // private Date outUnloadingTime;
    // /**
    // * 进口卸船时间
    // */
    // @Column(name = "UNLOADING_TIME")
    // private Date inUnloadingTime;
    /**
     * 船名
     */
    @Column(name = "SHIP_NAME")
    private String shipName;
    /**
     * 航次
     */
    @Column(name = "VOYAGES")
    private String voyages;

    /**
     * PI号
     */
    @Column(name = "PI")
    private String pi;

    public String getPi() {
        return pi;
    }

    public void setPi(String pi) {
        this.pi = pi;
    }

    /**
     * 通过booking的字符串形式生成booking
     */
    public Booking(String bookingString) {
        super();
        fromString(bookingString);
    }

    /**
     * 构造方法
     */
    public Booking() {
        super();
    }

    // public String getId() {
    // return id;
    // }
    //
    // public void setId(String id) {
    // this.id = id;
    // }

    public List<Goods> getGoodses() {
        return goodses;
    }

    public void setGoodses(List<Goods> goodses) {
        this.goodses = goodses;
    }

    public Contacter getConsignee() {
        return consignee;
    }

    public void setConsignee(Contacter consignee) {
        this.consignee = consignee;
    }

    public Company getShipping() {
        return shipping;
    }

    public void setShipping(Company shipping) {
        this.shipping = shipping;
    }

    public String getBusinessType() {
        return businessType;
    }

    public void setBusinessType(String businessType) {
        this.businessType = businessType;
    }

    public String getStPort() {
        return stPort;
    }

    public void setStPort(String stPort) {
        this.stPort = stPort;
    }

    public String getArPort() {
        return arPort;
    }

    public void setArPort(String arPort) {
        this.arPort = arPort;
    }

    public String getShipDate() {
        return shipDate;
    }

    public void setShipDate(String shipDate) {
        this.shipDate = shipDate;
    }

    public String getCtNumType() {
        return ctNumType;
    }

    public void setCtNumType(String ctNumType) {
        this.ctNumType = ctNumType;
    }

    public String getPrice() {
        return price;
    }

    public void setPrice(String price) {
        this.price = price;
    }

    public String getRemark() {
        return remark;
    }

    public void setRemark(String remark) {
        this.remark = remark;
    }

    public String getSo() {
        return so;
    }

    public void setSo(String so) {
        this.so = so;
    }

    public Date getCtDate() {
        return ctDate;
    }

    public void setCtDate(Date ctDate) {
        this.ctDate = ctDate;
    }

    public Date getHdDate() {
        return hdDate;
    }

    public void setHdDate(Date hdDate) {
        this.hdDate = hdDate;
    }

    public Attachment getSoDoc() {
        return soDoc;
    }

    public void setSoDoc(Attachment soDoc) {
        this.soDoc = soDoc;
    }

    public String getBookingState() {
        return bookingState;
    }

    public void setBookingState(String bookingState) {
        this.bookingState = bookingState;
    }

    public Date getGfDate() {
        return gfDate;
    }

    public void setGfDate(Date gfDate) {
        this.gfDate = gfDate;
    }

    public String getOperationType() {
        return operationType;
    }

    public void setOperationType(String operationType) {
        this.operationType = operationType;
    }

    public String getShipName() {
        return shipName;
    }

    public void setShipName(String shipName) {
        this.shipName = shipName;
    }

    public String getVoyages() {
        return voyages;
    }

    public void setVoyages(String voyages) {
        this.voyages = voyages;
    }

    /*
     * (non-Javadoc)
     * @see com.mrd.gtimp.business.entity.BaseBusiness#fromString(java.lang.String)
     */
    @Override
    public BaseBusiness fromString(String businessString) {
        return null;
    }

    /*
     * (non-Javadoc)
     * @see com.mrd.gtimp.business.entity.BaseBusiness#toString()
     */
    @Override
    public String toString() {
        return null;
    }

    public List<Container> getContainers() {
        return containers;
    }

    public void setContainers(List<Container> containers) {
        this.containers = containers;
    }

    @Override
    public void clearPk() throws Exception {
        PkConfig[] configs = {new PkConfig("id", String.class),
                new PkConfig("CREATOR", String.class), new PkConfig("CTIME|O", Date.class),
                new PkConfig("MODIFIER", String.class), new PkConfig("MTIME|O", Date.class),
                new PkConfig("CONFIRM_TIME|O", Date.class),
                new PkConfig("VALIDATE_TIME|O", Date.class),
                new PkConfig("validator_ext", String.class),
                new PkConfig("validator|O", User.class), new PkConfig("upload_time|O", Date.class),
                new PkConfig("uploader_ext", String.class), new PkConfig("uploader|O", User.class),
                new PkConfig("finish_time|O", Date.class),
                new PkConfig("finisher_ext", String.class), new PkConfig("finisher|O", User.class),
                new PkConfig("so", String.class), new PkConfig("ctDate|O", Date.class),
                new PkConfig("hdDate|O", Date.class), new PkConfig("soDoc|O", Attachment.class),
                new PkConfig("bookingState", String.class),
                new PkConfig("soDoc|O", Attachment.class)};// new PkConfig("containers|O",
        // List.class) };
        PkCleanerUtil.clearPk(this, configs);
        for (Goods g : goodses) {
            PkConfig[] gconfigs = {new PkConfig("id", String.class),
                    new PkConfig("booking|O", Booking.class)};
            PkCleanerUtil.clearPk(g, gconfigs);
        }
    }

}
